/**
 * Copyright (c) 2010 Simple Graph Tools contributors. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * $Id$
 */
package org.sgt.coredef.util;

import java.util.Set;

import org.sgt.coredef.Chain;
import org.sgt.coredef.Graph;


/**
 * Interface for a GraphWalker policy.
 * The policy is used by the walker (a {@link GraphWalker})
 * to build and grow chains in a given Graph.
 * 
 * @author Anne BUTTIGHOFFER
 *
 */
public interface IGraphWalkerPolicy {
	
	/**
	 * Creates a new Chain with start and end set as
	 * defined by the given route and returns it.
	 * <BR/><EM>Unspecified : the new Chain
	 * may or may not be attached to any EMF container.
	 * <BR/>See implementation documentation for this.</EM>
	 * @param route {@link Route}
	 * @param graph {@link Graph}
	 * @return created chain.
	 */
	Chain createNewChain(final Route route, final Graph graph);

	/**
	 * Determines whether given chain, in the context of given graph,
	 * can be grown in the forward direction. If true is returned,
	 * a call to {@link #growForward(Chain, Graph)} is granted to return
	 * a non empty Set.<BR/><BR/>
	 * <EM>Implementation : this method must grant that
	 * the final node as listed by {@link ChainHelper#getLastListedNode(Chain)}
	 * 	<UL>
	 * 		<LI>is at least the source of one Edge contained in the graph</LI>
	 * 		<LI>this edge has a node contained in the graph as destination</LI>
	 * 	</UL>
	 * </EM>
	 * @param seed {@link Chain}
	 * @param graph {@link Graph}
	 * @return true only if chain growth is possible.
	 */
	boolean canGrowForward(final Chain seed, final Graph graph);

	/**
	 * Returns a Set of Chains corresponding to all possibilities
	 * of growth in the forward direction of the given chain.
	 * The returned set is granted to be empty only if the 
	 * {@link #canGrowForward(Chain, Graph)} method would return true.
	 * @param seed {@link Chain}
	 * @param graph {@link Graph}
	 * @return Set of Chains representing the seed's growth possibilities
	 */
	Set<Chain> growForward(final Chain seed, final Graph graph);

	/**
	 * Determines whether given chain, in the context of given graph,
	 * can be grown in the backward direction. If true is returned,
	 * a call to {@link #growBackward(Chain, Graph)} is granted to return
	 * a non empty Set.<BR/><BR/>
	 * <EM>Implementation : this method must grant that
	 * the first node as listed by {@link ChainHelper#getLastListedNode(Chain)}
	 * 	<UL>
	 * 		<LI>is at least the destination of one Edge 
	 * contained in the graph</LI>
	 * 		<LI>this edge has a node contained in the graph 
	 * as source</LI>
	 * 	</UL>
	 * </EM>
	 * @param seed {@link Chain}
	 * @param graph {@link Graph}
	 * @return true only if chain growth is possible.
	 */
	boolean canGrowBackwards(final Chain seed, final Graph graph);

	/**
	 * Returns a Set of Chains corresponding to all possibilities
	 * of growth in the backward direction of the given chain.
	 * The returned set is granted to be empty only if the 
	 * {@link #canGrowBackwards(Chain, Graph)} method would return true.
	 * @param seed {@link Chain}
	 * @param graph {@link Graph}
	 * @return Set of Chains representing the seed's growth possibilities
	 */
	Set<Chain> growBackwards(final Chain seed, final Graph graph);

	/**
	 * Returns a String representation of the given Chain
	 * suitable for user display.
	 * @param seed the {@link Chain} to represent.
	 * @return a string representation of Chain.
	 */
	String prettyPrint(final Chain seed);
}
